package com.project.class8_18;

public class ThreadTest {
    public static void main(String[] args) {
        Thread1 t1 = new Thread1();
        //启动线程，线程启动后会执行run
        t1.start();

        //创建线程对象，传入Runnable实现类对象。线程启动后，会执行Runnable实现类的run()
        Thread t2 = new Thread(new Thread2());
        t2.start();

        for(int i=0;i<10;i++){
            System.out.println(i);

            try {
                //线程休眠100毫秒后继续运行
                Thread.sleep(100);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }


    }
}

class Thread1  extends Thread{
    @Override
    public void run() {
        for(int i=10;i<20;i++){
            System.out.println(i);

            try {
                Thread.sleep(100);
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    }
}

class Thread2 implements Runnable{

    @Override
    public void run() {
        for(int i=20;i<30;i++){
            System.out.println(i);
            try {
                Thread.sleep(100);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
    }
}